Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bloom): aggregate bloom filters #2340

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sistemd
Copy link
Contributor

@sistemd sistemd commented Oct 29, 2024

This PR adds code for aggregate bloom filters. It doesn't do anything useful with the code, but under a conditional flag it will compare the results obtained from aggregate bloom filters with results obtained from regular bloom filters to ensure that the implementation is correct.

The bit matrix is implemented manually because somehow it's 10x faster this way than using the bitvec crate and also it's extremely simple. I have a hunch that we could get even more improvements if we used u32 instead of u8 to back the bit matrix. But this can be done later.

The next PR will implement storing these aggregate filters in the DB, and then the final PR will implement actually using them from the RPC calls (and finally reaping the benefits).

@sistemd sistemd requested a review from a team as a code owner October 29, 2024 11:48
@sistemd sistemd force-pushed the sistemd/aggregate-bloom-filters branch from 8789370 to 39d5490 Compare October 29, 2024 11:52
@sistemd
Copy link
Contributor Author

sistemd commented Oct 30, 2024

I have a hunch that we could get even more improvements if we used u32 instead of u8 to back the bit matrix. But this can be done later.

However, the problem with this is that we still store/load Vec<u8> from the DB, and converting that to Vec<u32> safely requires copying. So it may actually turn out to be slower.

@CHr15F0x
Copy link
Member

I have a hunch that we could get even more improvements if we used u32 instead of u8 to back the bit matrix. But this can be done later.

However, the problem with this is that we still store/load Vec<u8> from the DB, and converting that to Vec<u32> safely requires copying. So it may actually turn out to be slower.

  • If the copying happens only once it shouldn't have any impact.
  • You could even try usize to match the word width.

@sistemd
Copy link
Contributor Author

sistemd commented Oct 31, 2024

You could even try usize to match the word width.

Good idea!

@@ -13,18 +75,185 @@ use crate::ReorgCounter;
// filter.
pub const EVENT_KEY_FILTER_LIMIT: usize = 16;

/// An aggregate of all Bloom filters for a given range of blocks.
/// Before being added to `AggregateBloom`, each [`BloomFilter`] is
/// rotated by 90 degrees.
Copy link
Member

@CHr15F0x CHr15F0x Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I guess the correct mathematical wording would be transposition.

Suggested change
/// rotated by 90 degrees.
/// rotated by 90 degrees (transposed).

Copy link
Member

@CHr15F0x CHr15F0x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🙇

I'm curious to see how it boosts some really slow event queries in the rpc 👀 .

@sistemd sistemd force-pushed the sistemd/aggregate-bloom-filters branch from 39d5490 to 32b48ae Compare November 1, 2024 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants